﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class SpyjControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        TextBox txtCsyj;//初审意见
        TextBox txtChyj;//初核意见
        TextBox txtFsyj;//复审意见
        TextBox txtHsyj;//核审意见

        Button btnInsert;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            txtCsyj = (TextBox)FindControl("txtCsyj");
            txtChyj = (TextBox)FindControl("txtChyj");
            txtFsyj = (TextBox)FindControl("txtFsyj");
            txtHsyj = (TextBox)FindControl("txtHsyj");

            btnInsert = (Button)FindControl("btnInsert");
            btnInsert.Click += new EventHandler(btnInsert_Click);
            base.OnLoad(e);
            if (!base.Page.IsPostBack) 
            {
                string strType = base.Page.Request["type"];
                Label labTitle = (Label)FindControl("labTitle");
                switch (strType)
                {
                    case "lxsq":
                        labTitle.Text = "立项审批";
                        break;
                    case "fwdj":
                        labTitle.Text = "范围内冻结审批";
                        break;
                    case "bcfa":
                        labTitle.Text = "补偿方案审批";
                        break;
                    case "bcss":
                        labTitle.Text = "补偿实施方案审批";
                        break;
                    case "xkjd":
                        labTitle.Text = "许可决定下达审批";
                        break;
                }

                IsLookPerson(strType);
            }
            
        }
        

        private void IsLookPerson(string strType)
        {
            string sql = string.Empty;

            if (strType == "xkjd")
            {
                sql = string.Format("Select * from ZS_PRONO where id='{0}'", base.Page.Request["ID"]);
            }
            else
            {
                sql = string.Format("Select * from zs_project where id='{0}'", base.Page.Request["ID"]);
            }
            
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                string strShzt = string.Empty;
                switch (strType)
                {
                    case "lxsq":
                        strShzt = dt.Rows[0]["审批状态"].ToString();
                        txtCsyj.Text = dt.Rows[0]["LX_CSYJ"].ToString();
                        txtChyj.Text = dt.Rows[0]["LX_CHYJ"].ToString();
                        txtFsyj.Text = dt.Rows[0]["LX_FSYJ"].ToString();
                        txtHsyj.Text = dt.Rows[0]["LX_HSYJ"].ToString();
                        break;
                    case "fwdj":
                        strShzt = dt.Rows[0]["冻结审批状态"].ToString();
                        txtCsyj.Text = dt.Rows[0]["DJ_CSYJ"].ToString();
                        txtChyj.Text = dt.Rows[0]["DJ_CHYJ"].ToString();
                        txtFsyj.Text = dt.Rows[0]["DJ_FSYJ"].ToString();
                        txtHsyj.Text = dt.Rows[0]["DJ_HSYJ"].ToString();
                        break;
                    case "bcfa":
                        strShzt = dt.Rows[0]["补偿审批状态"].ToString();
                        txtCsyj.Text = dt.Rows[0]["BCFA_CSYJ"].ToString();
                        txtChyj.Text = dt.Rows[0]["BCFA_CHYJ"].ToString();
                        txtFsyj.Text = dt.Rows[0]["BCFA_FSYJ"].ToString();
                        txtHsyj.Text = dt.Rows[0]["BCFA_HSYJ"].ToString();
                        break;
                    case "bcss":
                        strShzt = dt.Rows[0]["补偿实施审批状态"].ToString();
                        txtCsyj.Text = dt.Rows[0]["BCSS_CSYJ"].ToString();
                        txtChyj.Text = dt.Rows[0]["BCSS_CHYJ"].ToString();
                        txtFsyj.Text = dt.Rows[0]["BCSS_FSYJ"].ToString();
                        txtHsyj.Text = dt.Rows[0]["BCSS_HSYJ"].ToString();
                        break;
                    case "xkjd":
                        strShzt = dt.Rows[0]["审核状态"].ToString();
                        txtCsyj.Text = dt.Rows[0]["XK_CSYJ"].ToString();
                        txtChyj.Text = dt.Rows[0]["XK_CHYJ"].ToString();
                        txtFsyj.Text = dt.Rows[0]["XK_FSYJ"].ToString();
                        txtHsyj.Text = dt.Rows[0]["XK_HSYJ"].ToString();
                        break;
                }

                switch (strShzt)
                {
                    case "0":
                        txtCsyj.Enabled = true;
                        break;
                    case "-1"://核审
                        txtHsyj.Enabled = true;
                        break;
                    case "-2"://复审
                        txtFsyj.Enabled = true;
                        break;
                    case "-3"://初核
                        txtChyj.Enabled = true;
                        break;
                }
            }
        }

        protected void btnInsert_Click(object sender, EventArgs e)
        {
            string strId = base.Page.Request["ID"];
            string strType = base.Page.Request["type"];
            string sql = string.Empty;

            if (!string.IsNullOrEmpty(strId)) {
                switch (strType)
                {
                    case "lxsq":
                        sql = string.Format("update zs_project set LX_CSYJ='{0}',LX_FSYJ='{1}',LX_HSYJ='{2}',LX_CHYJ='{3}',审批状态=decode(审批状态,0,-3,-3,-2,-2,-1,-1,1) where id='{4}'", txtCsyj.Text, txtFsyj.Text, txtHsyj.Text, txtChyj.Text,strId);
                        break;
                    case "fwdj":
                        sql = string.Format("update zs_project set DJ_CSYJ='{0}',DJ_FSYJ='{1}',DJ_HSYJ='{2}',DJ_CHYJ='{3}',冻结审批状态=decode(冻结审批状态,0,-3,-3,-2,-2,-1,-1,1) where id='{4}'", txtCsyj.Text, txtFsyj.Text, txtHsyj.Text, txtChyj.Text, strId);
                        break;
                    case "bcfa":
                        sql = string.Format("update zs_project set BCFA_CSYJ='{0}',BCFA_FSYJ='{1}',BCFA_HSYJ='{2}',BCFA_CHYJ='{3}',补偿审批状态=decode(补偿审批状态,0,-3,-3,-2,-2,-1,-1,1) where id='{4}'", txtCsyj.Text, txtFsyj.Text, txtHsyj.Text, txtChyj.Text, strId);
                        break;
                    case "bcss":
                        sql = string.Format("update zs_project set BCSS_CSYJ='{0}',BCSS_FSYJ='{1}',BCSS_HSYJ='{2}',BCSS_CHYJ='{3}',补偿实施审批状态=decode(补偿实施审批状态,0,-3,-3,-2,-2,-1,-1,1) where id='{4}'", txtCsyj.Text, txtFsyj.Text, txtHsyj.Text, txtChyj.Text, strId);
                        break;
                    case "xkjd":
                        sql = string.Format("update ZS_PRONO set XK_CSYJ='{0}',XK_FSYJ='{1}',XK_HSYJ='{2}',XK_CHYJ='{3}',审核状态=decode(审核状态,0,-3,-3,-2,-2,-1,-1,1) where id='{4}'", txtCsyj.Text, txtFsyj.Text, txtHsyj.Text, txtChyj.Text, strId);
                        break;
                }

                if (!string.IsNullOrEmpty(sql))
                {
                    _EluZSDataProvider.RunSqlNon(sql);
                    base.Page.ClientScript.RegisterStartupScript(this.GetType(), "be", "<script>alert('保存成功！');window.opener.location.href =window.opener.location.href;window.close();</script>");
                }

            }
        }
    }
}


